package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/geofence")
public class GeofenceController {
    @Autowired
    private GeofenceService geofenceService;
    //按ctrl+点方法名去业务层接口的该方法 按ctrl+alt+点方法名去业务层实现类的该方法
    @GetMapping("/select")
    public JsonResult selectGeofence(GeofenceQuery geofenceQuery) {
        log.debug("查询围栏列表业务:geofenceQuery={}", geofenceQuery);
        List<GeofenceVO> list = geofenceService.selectGeofence(geofenceQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    public JsonResult saveGeofence(GeofenceSaveParam geofenceSaveParam) {
        log.debug("保存围栏业务:geofenceSaveParam={}", geofenceSaveParam);
        geofenceService.saveGeofence(geofenceSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteGeofence(@PathVariable Long id){
        log.debug("删除围栏业务:id={}",id);
        geofenceService.deleteGeofence(id);
        return JsonResult.ok();
    }

}
